package com.nuanshui.heatedloan.credit.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.nuanshui.framework.utils.LogUtil;
import com.nuanshui.heatedloan.constant.RabbitMqQueue;
import com.nuanshui.heatedloan.credit.facade.ExecuteCustomAuthService;
import com.nuanshui.heatedloan.credit.response.CalculationLimitResponse;
import com.nuanshui.heatedloan.middleware.rabbitmq.annotation.MqMessageHandler;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by wangxw on 2017/8/4.
 * 计算额度回调
 *
 *
 */

@MqMessageHandler(RabbitMqQueue.RABBIT_MQ_CALL_CALCULATION_LIMIT)
public class CalculationLimitHandler {

    private Logger logger = LoggerFactory.getLogger(CalculationLimitHandler.class);

    @Autowired
    private ExecuteCustomAuthService executeCustomAuthService;

    public void onMessage(Message message, Channel channel) throws Exception{
        try{
            LogUtil.info(logger, "----------执行风控计算额度返回消息队列开始----------");
            String msg = new String(message.getBody());
            CalculationLimitResponse calculationLimitResponse=JSON.parseObject(msg,CalculationLimitResponse.class);
            executeCustomAuthService.callBackCalculationLimit(calculationLimitResponse);
            LogUtil.info(logger, "----------完成风控计算额度返回消息队列开始----------");
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }
    }
}
